home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / saveBrushToShelf.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  26.0 KB  |  789 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  1998
  22. //  Author:         DRB & APP
  23. //
  24.  
  25. // IF YOU ARE CHANGING THE NAMES OF THESE VARIABLES YOU
  26. // MUST ALSO CHANGE THEIR NAMES IN OTHER MEL FILES WHERE THEY
  27. // ARE REFERENCED! (ie. setPresetTmpIcon.mel) APP 17mar99
  28. global string $gTmpPaintPresetShelveButton;
  29. global string $gTmpPaintPresetLabelField;
  30. global string $gTmpPaintPresetOverlayField;
  31. global int $gBrushPresetWinUpdateJob;
  32. global string $gSaveBrushToShelf;
  33. global string $gTmpVisorDirField;
  34. global int $gBrushCount = 1;
  35.  
  36. proc string makeNTPath( string $path ) {
  37.     string $retPath = `substitute "/" $path  "\\\\"`;
  38.     string $c = `match  "/" $retPath `;
  39.     while ( $c != "" ) {
  40.         $retPath = `substitute "/" $retPath  "\\\\"`;
  41.         $c = `match "/" $retPath `;
  42.     }
  43.     return $retPath;
  44. }
  45.  
  46. proc string getPfxImageLocation( string $imageName )
  47. {
  48.     // We Added this routine because the following line
  49.     // failed to find images in the brushImages directory.-DB
  50.  
  51.     string $fullPath = `file -q -loc $imageName`;
  52.     if( $fullPath == "unknown" ){
  53.         string $visorBase = `getenv "MAYA_LOCATION"`;
  54.         if ($visorBase != "") {
  55.             $fullPath = `file -q -loc ($visorBase + "/brushImages/" + $imageName)`;
  56.         }
  57.         if( $fullPath == "unknown" ){
  58.             string $iconDir  = `internalVar -userBitmapsDir`;
  59.             if( $iconDir != "" ){
  60.                 string $brushImagePath = ($iconDir + "brushImages/");
  61.                 $brushImagePath = substitute( "/icons", $brushImagePath, "");
  62.                 $fullPath = `file -q -loc ($brushImagePath + $imageName)`;
  63.             }
  64.         }
  65.     }
  66.     return $fullPath;
  67. }
  68.  
  69. //
  70. // This routine makes use of many system dependent utilities like copy, mkdir, delete, etc.
  71. // It really should make use of as many MEL commands to do this as possible instead of the
  72. // conditional operating system dependent code. APP 11may01
  73. global proc saveBrushPreset()
  74. {
  75.     // IF YOU ARE CHANGING THE NAMES OF THESE VARIABLES YOU
  76.     // MUST ALSO CHANGE THEIR NAMES IN OTHER MEL FILES WHERE THEY
  77.     // ARE REFERENCED! (ie. setPresetTmpIcon.mel) APP 17mar99
  78.     global string $gTmpPaintPresetShelveButton;
  79.     global string $gTmpPaintPresetLabelField;
  80.     global string $gTmpPaintPresetOverlayField;
  81.     global string $gShelfTopLevel;
  82.     global string $gSaveBrushToShelf;
  83.     global string $gTmpVisorDirField;
  84.     global int      $gBrushCount;
  85.     int $i;
  86.  
  87.     // gSelectDir is a flag to identify whether the 
  88.     // directory is selected thro' text field or fileBrowser
  89.  
  90.     global int $gSelectDir;
  91.     global string $gVisorSelectedDirectory;
  92.     global string $gLastPresetDir;
  93.  
  94.     $shelfLayout = $gShelfTopLevel;
  95.  
  96.     if (`radioButtonGrp -q -sl $gSaveBrushToShelf` != 1 && `about -evalVersion`){
  97.         // Because fopen and fprint are disabled in PLE, 
  98.         // saveBrushPreset to Visor is not supported.
  99.         warning ("saveBrushPreset to Visor is not supported in Maya PLE.");
  100.         return;
  101.     }
  102.     
  103.     if (`tabLayout -exists $shelfLayout` == 0) 
  104.     {
  105.         error ("saveBrushPreset: Error, can't find current shelf: " + $shelfLayout );
  106.         return; 
  107.     }
  108.  
  109.     string $brushName = `getDefaultBrush`;
  110.  
  111.     if (`nodeType $brushName` != "brush" ) 
  112.     {
  113.         error ("saveBrushPreset: Error, can't find template brush: " + $brushName );
  114.         return;
  115.     }
  116.  
  117.     string $label = 
  118.         `textFieldGrp -q -tx $gTmpPaintPresetLabelField`;
  119.     string $overlay = 
  120.         `textFieldGrp -q -tx $gTmpPaintPresetOverlayField`;
  121.  
  122.     if( $label == ("brush" + $gBrushCount) )
  123.         $gBrushCount++;
  124.  
  125.     string $tmpIcon  = `shelfButton -q -i1 $gTmpPaintPresetShelveButton`;
  126.     string $iconName = "userPaint.xpm";
  127.     string $tmpIconPath;
  128.  
  129.     string $brushImagePath;
  130.  
  131.     string $iconDir  = `internalVar -userBitmapsDir`;
  132.     string $prefDir = `internalVar -userPrefDir`;
  133.             
  134.     if (`radioButtonGrp -q -sl $gSaveBrushToShelf` == 1) {
  135.         // The user wishes to save this preset to the shelf. (Not the visor).
  136.  
  137.         // Set the brushImage directory path appropriately.
  138.         $brushImagePath = ($iconDir + "brushImages/");
  139.         $brushImagePath = substitute( "/icons", $brushImagePath, "");
  140.  
  141.         if( $tmpIcon != $iconName )
  142.         {
  143.             $iconName = $label;
  144.             string $iconPathName = ($iconDir + $iconName);
  145.             if(`about -mac`)
  146.                 $iconPathName += ".iff";  // Mac gives the grabbe image as iff and uses it as it is.
  147.             else
  148.                 $iconPathName += ".xpm";
  149.  
  150.             if( `file -q -ex $iconPathName` )
  151.             {
  152.                 // So, like, if there are more than 100 presets of the same name already,
  153.                 // we just keep overwriting the same icon. Just so you know. APP
  154.                 for( $i = 0; $i < 100; $i++ )
  155.                 {
  156.                     string $newName = ($iconName + $i);
  157.                     $iconPathName = ($iconDir + $newName);
  158.                     if(`about -mac`)
  159.                         $iconPathName += ".iff";
  160.                     else
  161.                         $iconPathName += ".xpm";
  162.                         
  163.                     if( `file -q -ex $iconPathName` == 0 )
  164.                     {
  165.                         $iconName = $newName;
  166.                         break;
  167.                     }
  168.                 }
  169.             }
  170.             $tmpIconPath = ($iconDir + $tmpIcon);
  171.             if ( `about -nt` ) {
  172.                 // Even though the path may have been entered with '\', Maya has
  173.                 // replaced those with '/' which makes the following 'copy' not work.
  174.                 // So, we substitute bits of the string. APP 07apr99
  175.  
  176.                 string $NTIconPath = `substitute "/" $tmpIconPath  "\\\\"`;
  177.                 string $c = `match "/" $NTIconPath `;
  178.                 while ( $c != "" ) {
  179.                     $NTIconPath = `substitute "/" $NTIconPath  "\\\\"`;
  180.                     $c = `match "/" $NTIconPath `;
  181.                 }
  182.  
  183.                 string $NTIconPathName = `substitute "/" $iconPathName  "\\\\"`;
  184.                 $c = `match  "/" $NTIconPathName `;
  185.                 while ( $c != "" ) {
  186.                     $NTIconPathName = `substitute "/" $NTIconPathName  "\\\\"`;
  187.                     $c = `match "/" $NTIconPathName `;
  188.                 }
  189.  
  190.                 sysFile -copy $NTIconPathName $NTIconPath;
  191.             }
  192.             else if (`about -irix` || `about -linux` || `about -mac`) {
  193.                 sysFile -copy $iconPathName $tmpIconPath;
  194.             } else {
  195.                 warning("Unknown and unimplemented operating system in saveBrushToShelf.mel");
  196.             }
  197.  
  198.         }
  199.         string $currentShelf = `tabLayout -q -st $shelfLayout`;
  200.         string $buttonParent = ($shelfLayout + "|" + $currentShelf);
  201.         setParent $buttonParent;
  202.  
  203.         // Create a command for this button
  204.         string $shelfCommand = `createBrushPresetScript $brushName`;
  205.         $shelfCommand = $shelfCommand + "rename (getDefaultBrush()) " + $label +";";
  206.  
  207.         // Create a button on this shelf
  208.         string $bName = `shelfButton -parent $buttonParent`;
  209.         if(`about -mac`){
  210.             if(!gmatch( $iconName, "*.iff") ) {
  211.                 $iconName += ".iff";
  212.             }
  213.         }else{
  214.             if ( !gmatch( $iconName, "*.xpm") )
  215.             // If it does not have the .xpm extension, add it.
  216.             $iconName += ".xpm";
  217.         }
  218.         shelfButton 
  219.             -e
  220.             -command $shelfCommand
  221.             -label $label
  222.             -iol $overlay
  223.             -st "iconAndTextHorizontal"
  224.             -width `shelfLayout -q -cellWidth $currentShelf`
  225.             -height `shelfLayout -q -cellHeight $currentShelf`
  226.             -i1 $iconName 
  227.             $bName;
  228.     }
  229.     else {
  230.         // The user wishes that this brush be saved to Visor.
  231.         string $visorDir = `textFieldGrp -q -text $gTmpVisorDirField`;
  232.         // MAYA_LOCATION must be writable by the user for them to be able to save a preset to Visor.
  233.         string $visorBase = `getenv "MAYA_LOCATION"`;
  234.         if ($visorBase != "") {
  235.  
  236.             // Set the brushImage directory path appropriately.
  237.             $brushImagePath = ($visorBase + "/brushImages/");
  238.  
  239.             string $brushDir;
  240.  
  241.             if($gSelectDir)
  242.             {
  243.                 // Directory is selected through fileBrowser.
  244.             
  245.                 if ($visorDir != "")
  246.                 {
  247.                     $brushDir = ($visorDir +"/");
  248.                     string $visorEd = "visorPanel1VisorEd";
  249.                 }
  250.                 else
  251.                 {
  252.                     $brushDir = ($prefDir + "brushes/");
  253.                 }
  254.             }
  255.             else
  256.             {
  257.                 // Directory name is entered in the Text Field.            
  258.                 if ($visorDir != "") {
  259.                     $brushDir = ($prefDir + "brushes/" + $visorDir +"/");
  260.                     //$brushDir = ($visorBase + "/brushes/" + $visorDir + "/");
  261.                     //If the $visorDir directory does not exist, create on and add to visor.
  262.                     string $visorEd = "visorPanel1VisorEd";
  263.                 }
  264.                 else {
  265.                     $brushDir = ($prefDir + "brushes/");
  266.                     //$brushDir = ($visorBase + "/brushes/");
  267.                 }
  268.             }
  269.  
  270.                // if $brushDir doesn't exists, create it.
  271.             if(`file -q -ex $brushDir` == 0)
  272.             {
  273.                 sysFile -makeDir $brushDir;
  274.             }
  275.  
  276.             //if(`about -mac`) // deliberately NT is avoided here.
  277.             //    $brushDir = unconvert($brushDir);
  278.             string $brushFile = ($label + ".mel");
  279.             string $iconFile;
  280.             if(`about -mac`)
  281.                 $iconFile = ($brushFile + ".iff");
  282.             else
  283.                 $iconFile = ($brushFile + ".icon");
  284.  
  285.             // Create a command for this button
  286.             string $shelfCommand = `createBrushPresetScript $brushName`;
  287.             $shelfCommand = $shelfCommand + "rename (getDefaultBrush()) " + $label +";";
  288.  
  289.             // Save this command to a file.
  290.             string $brushPathName = ($brushDir + $brushFile);
  291.  
  292.             if( `file -q -ex $brushPathName` )
  293.             {
  294.                 string    $result;
  295.                 $result = `confirmDialog -m ($brushPathName +" already exists. \n Do you want to replace it?") 
  296.                              -ma center -b "Yes" -b "No" -db "No" -title ("Save (" + $brushPathName + ")")`;
  297.  
  298.                 if($result == "No")
  299.                 {
  300.                     return;
  301.                 }
  302.  
  303.                 string $newName = ($label + ".mel");
  304.                 $brushPathName = ($brushDir + $newName);
  305.  
  306.                 if( `file -q -ex $brushPathName` == 0 )
  307.                 {
  308.                     $brushFile = $newName;
  309.                     if(`about -mac`)
  310.                         $iconFile = ($newName + ".iff");
  311.                     else
  312.                         $iconFile = ($newName + ".icon");            
  313.                 }
  314.             }
  315.  
  316.             // fopen seems to open it for write + append by default, so specify "w" to stop the append.
  317.             int $fileId = `fopen $brushPathName "w"`;
  318.             if ($fileId == 0) {
  319.                 error ("saveBrushPreset: Error, can't write to Visor file: " + $brushPathName );
  320.             }
  321.             else {
  322.                 fprint $fileId $shelfCommand;
  323.                 fclose $fileId;
  324.             }
  325.  
  326.             // Save the icon to the brushDir.
  327.             string $iconPathName = ($brushDir + $iconFile);
  328.             
  329.             $tmpIconPath = ($iconDir + $tmpIcon);
  330.             if(`about -mac`) // for Mac check for .iff and others .xpm.
  331.             {
  332.                 if ( gmatch( $tmpIconPath, "*.iff") ) {
  333.                     // If it does have the .iff extension, delete it.
  334.                     $tmpIconPath = substitute (".iff", $tmpIconPath , "");
  335.                 }
  336.             } else {
  337.                 if ( gmatch( $tmpIconPath, "*.xpm") ) {
  338.                 // If it does have the .xpm extension, delete it.
  339.                 $tmpIconPath = substitute (".xpm", $tmpIconPath , "");
  340.                 }
  341.             }
  342.             if(`about -mac`)
  343.                 $tmpIconPath += ".iff";
  344.             else
  345.             $tmpIconPath += ".rgb";
  346.             if ( `about -nt` ) {
  347.                 // Even though the path may have been entered with '\', Maya has
  348.                 // replaced those with '/' which makes the following 'copy' not work.
  349.                 // So, we substitute bits of the string. APP 07apr99
  350.  
  351.                 string $NTIconPath = makeNTPath( $tmpIconPath );
  352.  
  353.                 string $NTIconPathName = makeNTPath( $iconPathName );
  354.  
  355.                 sysFile -copy $NTIconPathName $NTIconPath;
  356.             }
  357.             else if (`about -irix` || `about -linux` || `about -mac`) {
  358.                 sysFile -copy $iconPathName $tmpIconPath;
  359.             } else {
  360.                 warning("Unknown and unimplemented operating system in saveBrushToShelf.mel");
  361.             }
  362.         }
  363.     }
  364.  
  365.     // Now we want to look at the template brush and find any file textures which are
  366.     // applied and copy them to the maya/#.#/prefs/icons directory.
  367.     string $imageName    = `getAttr ($brushName + ".imageName")`;
  368.     int    $useFrameExt  = `getAttr ($brushName + ".useFrameExtension")`;
  369.     string $leafImage    = `getAttr ($brushName + ".leafImage")`;
  370.     string $flowerImage  = `getAttr ($brushName + ".flowerImage")`;
  371.     string $tbip = "";
  372.  
  373.     if ( `about -nt` ) {
  374.         $tbip = $brushImagePath;
  375.         $brushImagePath = makeNTPath( $brushImagePath );
  376.     }
  377.     if ($imageName != "" || $leafImage != "" || $flowerImage != "") {
  378.         // Check to see if the brushImages/ directory exists.
  379.         if ( !`file -q -ex $brushImagePath` ) {
  380.             // If not, create it. There are no checks to see if this succeeds or fails
  381.             // because the system command does not return the status of commands, only their
  382.             // output. Bug logged to correct this.
  383.             sysFile -makeDir $brushImagePath;
  384.             if ( !`file -q -ex $brushImagePath` ) {
  385.                 warning("Unable to create the directory : " + $brushImagePath );
  386.             }
  387.         }
  388.     }
  389.  
  390.     if ( `file -q -ex $brushImagePath` ) {
  391.         if ( $imageName != "" ) {
  392.             string $buffer[];
  393.             $numTokens = `tokenize $imageName "/" $buffer`;
  394.             $imageName = $buffer[$numTokens-1];
  395.  
  396.             if ($useFrameExt) {
  397.                 // We will have to copy a number of files. Look for all files with the common root and
  398.                 // an extension and copy them.
  399.                 int $ext = `getAttr($brushName + ".frameExtension")`;
  400.                 string $buffer[];
  401.                 int $numTokens = tokenize( $imageName, ".", $buffer );
  402.  
  403.                 // Try to find if there is a numerical component to the input string.
  404.                 // If so, assume it is the fame number and extract it from the image name.
  405.                 if ($numTokens > 1) {
  406.                     int $i = 1;
  407.                     $imageName = $buffer[0];
  408.                     while ( $i < $numTokens ) {
  409.                         if (
  410.                             substring($buffer[$i],1,1) == "1" ||
  411.                             substring($buffer[$i],1,1) == "2" ||
  412.                             substring($buffer[$i],1,1) == "3" ||
  413.                             substring($buffer[$i],1,1) == "4" ||
  414.                             substring($buffer[$i],1,1) == "5" ||
  415.                             substring($buffer[$i],1,1) == "6" ||
  416.                             substring($buffer[$i],1,1) == "7" ||
  417.                             substring($buffer[$i],1,1) == "8" ||
  418.                             substring($buffer[$i],1,1) == "9" ||
  419.                             substring($buffer[$i],1,1) == "0" ||
  420.                             substring($buffer[$i],1,1) == "#"
  421.                             ) {
  422.                             // It is numerical, we are assuming that this is the frame number.
  423.                             $i = $numTokens;
  424.                         } else {
  425.                             $imageName = $imageName + "." + $buffer[$i];
  426.                         }
  427.                         ++$i;
  428.                     }
  429.                 }
  430.                 string $fullPath = getPfxImageLocation($imageName + "." + $ext);
  431.  
  432.                 // Truncate the extension.
  433.                 $fullPath = `substitute ("." + $ext) $fullPath ""`;
  434.                 string $files;
  435.                 string $fileList[] = `getFileList -fld $fullPath -fs "*.*"`;
  436.                 $numTokens = size($fileList);
  437.                 
  438.                 if ( `about -nt` ) {
  439.                     $fullPath = unconvert( $fullPath );
  440.                     $fullPath = `substitute $imageName $fullPath ""`;
  441.                 }
  442.                 
  443.                 // Iterate on $fileList and copy them to $brushImagePath.
  444.                 
  445.                 if ($numTokens == 0 || ($numTokens == 1 && $fileList[0] == "unknown")) {
  446.                     warning("Cannot find source images for animated file texture to copy to the preset brush images directory.");
  447.                 } else {
  448.                     string $file;
  449.                     for ( $file in $fileList ) {
  450.                         string $filePath[];
  451.                         int $index = tokenize( $file, "/", $filePath );
  452.                         string $fullFileName = $fullPath + $filePath[$index-1];
  453.                         if ( `about -nt` ) {
  454.                             // Do not copy the file if it is already there.
  455.                             string $result = getPfxImageLocation($brushImagePath + "\\" + $filePath[$index-1]);
  456.                             if ($result == "unknown" || $result != ($tbip + $filePath[$index-1])) {
  457.                                 sysFile -copy $brushImagePath $fullFileName;
  458.                                 $file = unconvert( $file );
  459.                                 print ( "Copying image texture file " + $file + " to " + $tbip );
  460.                             }
  461.                         }
  462.                         else if (`about -irix` || `about -linux` || `about -mac`) {
  463.                             string $result = getPfxImageLocation($brushImagePath + $filePath[$index-1]);
  464.                             if ($result == "unknown" || $result != ($brushImagePath + $filePath[$index-1])) {
  465.                                 print ( "Copying image texture file " + $file + " to " + $brushImagePath );
  466.                                 sysFile -copy $brushImagePath $file;
  467.                             }
  468.                         } else {
  469.                             warning("Unknown and unimplemented operating system in saveBrushToShelf.mel");
  470.                         }
  471.                     }
  472.                 }
  473.             } else { // NOT if ($useFrameExt)
  474.                 // The name of the file is literal.
  475.                 string $fullPath = getPfxImageLocation( $imageName );
  476.                 if ($fullPath != "unknown") {
  477.                     if ( `about -nt` ) {
  478.                         string $mfullPath = makeNTPath( $fullPath );
  479.                         string $result = getPfxImageLocation ($brushImagePath + "\\" + $imageName);
  480.                         if ( $result == "unknown" || $result != ($tbip + $imageName)) {
  481.                             print ( "Copying image texture file " + $fullPath + " to " + $tbip );
  482.                             sysFile -copy  $brushImagePath $mfullPath;
  483.                         }
  484.                     }
  485.                     else if (`about -irix` || `about -linux` || `about -mac`) {
  486.                         string $result = getPfxImageLocation($brushImagePath + $imageName);
  487.                         if ($result == "unknown" || $result != ($brushImagePath + $imageName)) {
  488.                             print ( "Copying image texture file " + $fullPath + " to " + $brushImagePath );
  489.                             sysFile -copy $brushImagePath $fullPath;
  490.                         }
  491.                     } else {
  492.                         warning("Unknown and unimplemented operating system in saveBrushToShelf.mel");
  493.                     }
  494.                 } 
  495.             } // end of else portion of if ($useFrameExt)
  496.         } // end of $imageName != ""
  497.  
  498.         if ( $leafImage != "" ) {
  499.             string $buffer[];
  500.             $numTokens = `tokenize $leafImage "/" $buffer`;
  501.             $leafImage = $buffer[$numTokens-1];
  502.  
  503.             string $fullPath = getPfxImageLocation($leafImage);
  504.             if ($fullPath != "unknown") {
  505.                 if ( `about -nt` ) {
  506.                     string $mfullPath = makeNTPath( $fullPath );
  507.                     string $result = getPfxImageLocation($brushImagePath + "\\" + $leafImage);
  508.                     if ( $result == "unknown" || $result != ($tbip + $leafImage)) {
  509.                         sysFile -copy $brushImagePath $mfullPath;
  510.                         print ( "Copying leaf image texture file " + $fullPath + " to " +  $tbip );
  511.                     }
  512.                 }
  513.                 else if (`about -irix` || `about -linux`) {
  514.                     string $result = getPfxImageLocation($brushImagePath + $leafImage);
  515.                     if ( $result == "unknown" || $result != ($brushImagePath + $leafImage)) {
  516.                         print ( "Copying leaf image texture file " + $fullPath + " to " + $brushImagePath );
  517.                         sysFile -copy $brushImagePath $fullPath;
  518.                     }
  519.                 } else if(`about -mac`) {
  520.                     string $result = getPfxImageLocation($brushImagePath + $leafImage);
  521.                     if ( $result == "unknown" || $result != ($brushImagePath + $leafImage)) {
  522.                         print ( "Copying leaf image texture file " + $fullPath + " to " + $brushImagePath );
  523.                         sysFile -copy $brushImagePath $fullPath;
  524.                     }
  525.                 } else {
  526.                     warning("Unknown and unimplemented operating system in saveBrushToShelf.mel");
  527.                 }
  528.             } 
  529.         } // end $leafImage != ""
  530.  
  531.         if ( $flowerImage != "" ) {
  532.             // We should really only try to copy the image file if "Flower Use Branch Texture" is off, but...
  533.             string $buffer[];
  534.             $numTokens = `tokenize $flowerImage "/" $buffer`;
  535.             $flowerImage = $buffer[$numTokens-1];
  536.  
  537.             string $fullPath = getPfxImageLocation( $flowerImage );
  538.             if ($fullPath != "unknown") {
  539.                 if ( `about -nt` ) {
  540.                     string $mfullPath = makeNTPath( $fullPath );
  541.                     string $result = getPfxImageLocation ($brushImagePath + "\\" + $flowerImage);
  542.                     if ( $result == "unknown" || $result != ($tbip + $flowerImage)) {
  543.                         sysFile -copy $brushImagePath $mfullPath;
  544.                         print ( "Copying flower image texture file " + $fullPath + " to " + $tbip );
  545.                     }
  546.                 }
  547.                 else if (`about -irix` || `about -linux`) {
  548.                     string $result = getPfxImageLocation ($brushImagePath + $flowerImage);
  549.                     if ( $result == "unknown" || $result != ($brushImagePath + $flowerImage)) {
  550.                         print ( "Copying flower image texture file " + $fullPath + " to " + $brushImagePath );
  551.                         sysFile -copy $brushImagePath $fullPath;
  552.                     }
  553.                 } else if (`about -mac`) {
  554.                     string $result = getPfxImageLocation ($brushImagePath + $flowerImage);
  555.                     if ( $result == "unknown" || $result != ($brushImagePath + $flowerImage)) {
  556.                         print ( "Copying flower image texture file " + $fullPath + " to " + $brushImagePath );
  557.                         sysFile -copy $brushImagePath $fullPath;
  558.                     }
  559.                 } else {
  560.                     warning("Unknown and unimplemented operating system in saveBrushToShelf.mel");
  561.                 }
  562.             } 
  563.         } // end $flowerImage != ""
  564.     }
  565.  
  566.     //
  567.     // save the last used Visor Directory.
  568.     //
  569.     $gLastPresetDir = $gVisorSelectedDirectory;
  570.  
  571.     $gSelectDir = 0;
  572.     window -e -visible false brushPresetWin; 
  573.     dynPaintEditor -edit -iconGrab false dynPaintScriptedPanelEd;
  574. }
  575.  
  576. global proc updateBrushPresetWin()
  577. {
  578.     // IF YOU ARE CHANGING THE NAMES OF THESE VARIABLES YOU
  579.     // MUST ALSO CHANGE THEIR NAMES IN OTHER MEL FILES WHERE THEY
  580.     // ARE REFERENCED! (ie. setPresetTmpIcon.mel) APP 17mar99
  581.     global int $gBrushCount;
  582.     global string $gTmpPaintPresetShelveButton;
  583.     global string $gTmpPaintPresetLabelField;
  584.     global string $gTmpPaintPresetOverlayField;
  585.     global int $gBrushPresetWinUpdateJob;
  586.     global string $gTmpVisorDirField;
  587.  
  588.     if( !`window -exists brushPresetWin` ) 
  589.     {
  590.         return;
  591.     }
  592.  
  593.     string $brushName = `getDefaultBrush`;
  594.     string $userName;
  595.  
  596.     if( $brushName == "defaultBrush" )
  597.     {
  598.         $userName = "brush" + $gBrushCount;
  599.     }
  600.     else
  601.     {
  602.         $userName = $brushName;
  603.     }
  604.     textFieldGrp -e -text $userName $gTmpPaintPresetLabelField;
  605.     textFieldGrp -e -text $userName $gTmpPaintPresetOverlayField;
  606.     shelfButton -e -i1 "userPaint.xpm"  $gTmpPaintPresetShelveButton;
  607. }
  608.  
  609. global proc prepareIconGrab (string $editor)
  610. {
  611.     print ("// Click and drag in the Paint Effects window to grab the icon //");
  612.     dynPaintEditor -edit -iconGrab true $editor;
  613. }
  614.  
  615. global proc int visorDirSelCB( string $filename,
  616.                                  string $fileType )
  617. {
  618.     // Visor Directory selection callback function.
  619.     global string $gVisorSelectedDirectory;
  620.     global string $gTmpVisorDirField;
  621.     global int $gSelectDir;
  622.  
  623.     $gVisorSelectedDirectory = $filename;
  624.     textFieldGrp -e -text $gVisorSelectedDirectory $gTmpVisorDirField;
  625.     $gSelectDir = 1;
  626.  
  627.     return true;
  628. }
  629.  
  630. global proc openVisorFileBrowser()
  631. {
  632.     global string $gLastPresetDir;
  633.  
  634.     if(!`file -q -ex $gLastPresetDir`)
  635.     {
  636.         sysFile -makeDir $gLastPresetDir;
  637.     }
  638.  
  639.     workspace -dir $gLastPresetDir;
  640.     fileBrowser "visorDirSelCB" "Save Brush Preset" "" 4;
  641. }
  642.  
  643. global proc saveBrushToShelf()
  644. {
  645.     global string $gTmpPaintPresetShelveButton;
  646.     global string $gTmpPaintPresetLabelField;
  647.      global string $gTmpPaintPresetOverlayField;
  648.     global int $gBrushPresetWinUpdateJob;
  649.     global string $gSaveBrushToShelf;
  650.     global string $gTmpVisorDirField;
  651.  
  652.     global string $gVisorDirSelector;
  653.     global string $gVisorSelectedDirectory = "";
  654.     global int $gSelectDir = 0;
  655.  
  656.     //
  657.     // $gLastPresetDir remembers the last directory used for saving the Brush Preset.
  658.     //
  659.     global string $gLastPresetDir = "";
  660.  
  661.  
  662.     if($gLastPresetDir == "")
  663.     {
  664.         $gLastPresetDir = `internalVar -userPrefDir` + "brushes/";
  665.     }
  666.  
  667.     if( !`window -exists brushPresetWin` ) 
  668.     {
  669.         int $textFieldWidth;
  670.         window -t "Save Brush Preset" -w 410 -h 380 brushPresetWin;
  671.         formLayout fl;
  672.             columnLayout -adj true col1;
  673.                 formLayout -nd 100 psForm;
  674.                 $gTmpPaintPresetLabelField =
  675.                     `textFieldGrp -label "Label:"  tfg2`;
  676.                 $gTmpPaintPresetOverlayField =
  677.                     `textFieldGrp -label "Overlay Label:" tfg3`;
  678.  
  679.                 $gTmpPaintPresetShelveButton = `shelfButton shButTmp`;
  680.                 shelfButton -e -st "iconAndTextHorizontal"
  681.                     $gTmpPaintPresetShelveButton;
  682.  
  683.                 button -label "Grab Icon" -c "prepareIconGrab dynPaintScriptedPanelEd" gbBut;
  684.  
  685.                 $gSaveBrushToShelf = `radioButtonGrp -numberOfRadioButtons 2 -label "Save Preset:"
  686.                     -labelArray2 "To Shelf" "To Visor" -sl 1 sbts`;
  687.  
  688.                 $gTmpVisorDirField =
  689.                     `textFieldGrp -label "Visor Directory:"  -ed 0 tfg4`;
  690.                     
  691.                 $textFieldWidth = `textFieldGrp -q -width $gTmpVisorDirField`;
  692.  
  693.                 if($textFieldWidth <= 0)
  694.                 {
  695.                     // On Irix, the width is returned to be zero, but on other platforms
  696.                     // it is returning 380, so the default value of 380 is assigned.
  697.  
  698.                     $textFieldWidth = 380;
  699.                 }
  700.  
  701.                 $gVisorDirSelector = `symbolButton -c "openVisorFileBrowser" -i "navButtonBrowse.xpm" -en false tfg5`;
  702.  
  703.                 radioButtonGrp -e -on2 "textFieldGrp -e -ed 1 $gTmpVisorDirField;symbolButton -e -en true $gVisorDirSelector" $gSaveBrushToShelf;
  704.                 radioButtonGrp -e -of2 "textFieldGrp -e -ed 0 $gTmpVisorDirField;symbolButton -e -en false $gVisorDirSelector" $gSaveBrushToShelf;
  705.  
  706.                 formLayout -e 
  707.                     -af tfg2 right 0
  708.                     -af tfg2 left 0
  709.                     -af tfg2 top 7
  710.                     -an tfg2 bottom
  711.                             
  712.                     -af tfg3 right 0 
  713.                     -af tfg3 left 0
  714.                     -ac tfg3 top 7 tfg2
  715.                     -an tfg3 bottom
  716.                                 
  717.                     -af sbts left 0
  718.                     -af sbts right 0
  719.                     -ac sbts top 12 tfg3
  720.                     -an sbts bottom
  721.  
  722.                     -af tfg4 left 0
  723.                     -af tfg4 right 0
  724.                     -ac tfg4 top 2 sbts
  725.                     -an tfg4 bottom
  726.  
  727.                     -aof shButTmp right -95
  728.                     -an shButTmp left 
  729.                     -ac shButTmp top 2 tfg4
  730.                     -af shButTmp bottom 2
  731.                             
  732.                     -af gbBut left 140 
  733.                     -an gbBut right
  734.                     -ac gbBut top 4 tfg4
  735.                     -an gbBut bottom 
  736.  
  737.                     -af tfg5 left $textFieldWidth
  738.                     -an tfg4 right
  739.                     -ac tfg5 top 2 sbts
  740.                     -an tfg5 bottom 
  741.  
  742.  
  743.                     psForm;
  744.  
  745.         setParent fl;
  746.         separator -horizontal true shelfSeparator;
  747.         button
  748.             -label "Save Brush Preset"
  749.             -c "saveBrushPreset; dynPaintEditor -edit -iconGrab false dynPaintScriptedPanelEd"
  750.             saveBrushPresetButton;
  751.         button
  752.             -label "Close"
  753.             -c "window -e -visible false brushPresetWin; dynPaintEditor -edit -iconGrab false dynPaintScriptedPanelEd" 
  754.             closeBrushPresetEdButton;
  755.         formLayout -e
  756.             -af shelfSeparator "left" 0
  757.             -af shelfSeparator "right" 0
  758.             -ac shelfSeparator "bottom" 5 closeBrushPresetEdButton
  759.  
  760.             -af saveBrushPresetButton "left" 5
  761.             -af saveBrushPresetButton "bottom" 5
  762.             -ap saveBrushPresetButton "right" 3 50
  763.             -an saveBrushPresetButton "top"
  764.  
  765.             -ap closeBrushPresetEdButton "left" 2 50
  766.             -af closeBrushPresetEdButton "bottom" 5
  767.             -af closeBrushPresetEdButton "right" 5
  768.             -an closeBrushPresetEdButton "top"
  769.             fl;
  770.     }
  771.     updateBrushPresetWin();
  772.     showWindow brushPresetWin;
  773.     $gBrushPresetWinUpdateJob = `scriptJob -e SelectionChanged "brushPresetWinCallback"`;
  774.  
  775. }
  776.  
  777. global proc brushPresetWinCallback()
  778. {
  779.     global int $gBrushPresetWinUpdateJob;
  780.     if( !`window -exists brushPresetWin` 
  781.       || !`window -q -visible brushPresetWin` )
  782.     {
  783.         dynPaintEditor -edit -iconGrab false dynPaintScriptedPanelEd;
  784.         evalDeferred ("scriptJob -kill " +$gBrushPresetWinUpdateJob);
  785.         return;
  786.     }
  787.     updateBrushPresetWin();
  788. }
  789.